﻿using System.Collections.Generic;
using System.Linq;
using Devbridge.IPolice.DataContracts;
using Devbridge.IPolice.DomainModel;

namespace Devbridge.IPolice.RepositoriesMock
{
    public class PoliceOfficerRepositoryMock : IPoliceOfficerRepository
    {
        private readonly IList<PoliceOfficer> policeOfficers;

        public PoliceOfficerRepositoryMock()
        {
            policeOfficers = new List<PoliceOfficer>();

            var policeOfficer1 = new PoliceOfficer {Id = 1, FirstName = "Jonas", LastName = "Jonaitis", PhoneNumber = "+3706xxxxx1"};
            var policeOfficer2 = new PoliceOfficer { Id = 2, FirstName = "Petras", LastName = "Jonaitis", PhoneNumber = "+3706xxxxx2" };
            var policeOfficer3 = new PoliceOfficer { Id = 3, FirstName = "Petras", LastName = "Petraitis", PhoneNumber = "+3706xxxxx3" };

            policeOfficers.Add(policeOfficer1);
            policeOfficers.Add(policeOfficer2);
            policeOfficers.Add(policeOfficer3);
        }

        public void Remove<TEntity>(int id)
        {
            throw new System.NotImplementedException();
        }

        public PoliceOfficer GetById(int id)
        {
            PoliceOfficer policeOfficer = AllQuery().FirstOrDefault(p => p.Id == id);

            return policeOfficer;
        }

        public IQueryable<PoliceOfficer> AllQuery()
        {
            return policeOfficers.AsQueryable();
        }

        public void Remove(PoliceOfficer entity)
        {
            policeOfficers.Remove(entity);
        }

        public void Save(PoliceOfficer entity)
        {
            policeOfficers.Add(entity);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            policeOfficers.Clear();
        }
    }
}